package lhc.alg.top100;

/**
 * description: https://leetcode.cn/problems/jump-game/
 *  55 跳跃游戏
 *  理解成最值问题 用贪心思路
 * author: hongchen.liao
 * date:  2022/7/29
 */
public class _55_Jump_Game {

    class Solution {
        public boolean canJump(int[] nums) {
            int n = nums.length;
            int farthest = 0;
            for(int i = 0; i < n-1; i++){
                //不算计算能跳到的最远距离
                farthest = Math.max(farthest, i + nums[i]);
                //碰到0了 卡住不动了
                if(farthest <= i) return false;
            }
            return farthest >= n-1;
        }
    }

}
